package com.example.springboottest.example.kafka.simple.protostuff;

import com.example.springboottest.student.model.Student;
import io.protostuff.ProtostuffIOUtil;
import io.protostuff.Schema;
import io.protostuff.runtime.RuntimeSchema;
import org.apache.kafka.common.serialization.Deserializer;

import java.util.Map;

public class StudentProtostuffDeserializer implements Deserializer<Student> {
    @Override
    public void configure(Map<String, ?> configs, boolean isKey) {
    }

    @Override
    public Student deserialize(String topic, byte[] data) {
        if (data == null)
            return null;
        Schema schema = RuntimeSchema.getSchema(Student.class);
        Student ans = new Student();
        ProtostuffIOUtil.mergeFrom(data, ans, schema);
        return ans;
    }

    @Override
    public void close() {

    }
}
